package co.gov.medellin.ssti.sub.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
import org.springframework.beans.factory.annotation.Autowired;

import co.gov.medellin.ssti.sub.common.excepcion.SUBException;
import co.gov.medellin.ssti.sub.model.dao.exception.DAOException;
import co.gov.medellin.ssti.sub.model.service.CargueService;
import co.gov.medellin.ssti.sub.web.form.StrutsUploadForm;

/**
 * Struts File Upload Action Form.
 * 
 */
public class StrutsUploadAction extends Action {
	@Autowired
	CargueService cargueServiceImpl;

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		System.out.println("hey");
		StrutsUploadForm myForm = (StrutsUploadForm) form;

		// Process the FormFile
		FormFile myFile = myForm.getTheFile();
		// String contentType = myFile.getContentType();
		// String fileName = myFile.getFileName();
		// int fileSize = myFile.getFileSize();
		byte[] fileData = myFile.getFileData();

		try {
			int icargue = cargueServiceImpl.uploadFile(134, fileData);
		} catch (DAOException e) {
			SUBException.logDebugError("", e);
			throw e;
		}

		return mapping.findForward("success");
	}
}